import Vue from 'vue'
import VueRouter from 'vue-router'
import Me from "@c/user/Me"
import Home from "../views/Home";
import LoginForm from "../components/user/Login";
import RegisterForm from "../components/user/Register";
import Store from "../views/Store";

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    name: 'home',
    meta: {
      title: '首页',
    },
    component: Home
  },
  {
    path: '/home',
    name: 'home',
    meta: {
      title: '首页',
    },
    redirect: '/'
  },
  {
    path: '/store',
    name: 'store',
    meta: {
      title: '商城',
    },
    component: Store
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
    },
    component: LoginForm
  },
  {
    path: '/register',
    name: 'register',
    meta: {
      title: '注册',
    },
    component: RegisterForm
  },
  {
    path: '/me',
    name: 'me',
    meta: {
      title: '个人中心',
    },
    component: Me
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})
export default router
